package com.company.common.util;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
 * 将Map<String,Object>转化成Map<String,String>
 *
 * @author hekai
 * @date 2021/05/21 20:08
 */
public class MapStringUtil {

    public static Map<String,String> parseObjectMapToStringMap(Object o){
        //利用Hutools将对象转化成ObjectValueMap
        Map<String,Object> map =  BeanUtil.beanToMap(o);
        //序列化成JSON字符
        String objStr = JSONObject.toJSONString(map);
        //反序列化成Map<String,String>
        return JSONObject.parseObject(objStr, Map.class);
    }
}
